package jm.algorithm.recursion;

/**
 * @Description 上楼梯问题
 * @date 2022/5/18 8:54
 */
public class ClimbStairs {
    public static void main(String[] args) {
        System.out.println(test(6));
    }

    private static int test(int n){
        return climbStairs1(n);
    }

    private static int climbStairs1(int n){
        if (n <= 2) return n;
        return climbStairs1(n-1) + climbStairs1(n-2);
    }

    private static int climbStairs2(int n){
        if (n <= 2) return n;
        int first = 1;
        int second = 2;
        for (int i = 3; i < n; i++) {
            int tmp = first;
            first = second;
            second = tmp + second;
        }
        return second;
    }

}
